﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MacroRecorder
{
    class SerializableHelper
    {
        public static void Save<T>(T value, string filename)
        {
            var jsonstr = JsonConvert.SerializeObject(value, Formatting.Indented);
            using (FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write))
            {
                using (TextWriter writer = new StreamWriter(file, new UTF8Encoding()))
                    writer.Write(jsonstr);
            }
        }
        public static T Read<T>(string filename)
        {
            return JsonConvert.DeserializeObject<T>(File.ReadAllText(filename));
        }
    }
}
